/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.util.ObjectUtil
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.beans.value.ChangeListener
 *  javafx.beans.value.ObservableValue
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  javafx.scene.control.TextField
 *  javafx.scene.layout.AnchorPane
 *  org.springframework.beans.factory.annotation.Autowired
 */
package com.gys.controller.salesReceipts;

import cn.hutool.core.util.ObjectUtil;
import com.gys.common.util.CommonUtil;
import com.gys.controller.BaseController;
import com.gys.controller.dataManger.ControllerManger;
import com.gys.controller.salesReceipts.SalesReceiptsMainController;
import com.gys.data.salesReceipts.GetSalesReceiptsTableOutData;
import de.felixroske.jfxsupport.FXMLController;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import org.springframework.beans.factory.annotation.Autowired;

@FXMLController
public class TieNumController
extends BaseController
implements Initializable {
    @FXML
    private TextField num;
    @FXML
    private AnchorPane pane;
    @Autowired
    private SalesReceiptsMainController salesReceiptsMainController;

    public void initialize(URL location, ResourceBundle resources) {
        ControllerManger.controllerMap.put(this.getClass().getSimpleName(), this);
        this.num.textProperty().addListener((ChangeListener)new ChangeListener<String>(){

            public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
                if (ObjectUtil.isNotEmpty(newValue) && !CommonUtil.positiveInteger(newValue) || newValue.length() > 5) {
                    TieNumController.this.num.setText(oldValue);
                }
            }
        });
        this.init();
    }

    @Override
    public void init() {
        if (ObjectUtil.isEmpty(this.pane)) {
            return;
        }
        this.num.clear();
    }

    @FXML
    private void sureAction() {
        if (ObjectUtil.isEmpty(this.num.getText())) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u5e16\u6570\u4e0d\u80fd\u4e3a\u7a7a");
            alert.showAndWait();
            return;
        }
        GetSalesReceiptsTableOutData selectedItem = (GetSalesReceiptsTableOutData)this.salesReceiptsMainController.getTableView().getSelectionModel().getSelectedItem();
        String itemNum = selectedItem.getNum();
        if (itemNum.contains("*")) {
            String[] split = itemNum.split("\\*");
            selectedItem.setNum(split[0] + "*" + this.num.getText());
        } else {
            selectedItem.setNum(selectedItem.getNum() + "*" + this.num.getText());
        }
        String num = selectedItem.getNum();
        Float money = Float.valueOf(Float.valueOf(selectedItem.getPrice()).floatValue() * (float)Integer.valueOf(num.split("\\*")[0]).intValue() * (float)Integer.valueOf(num.split("\\*")[1]).intValue());
        selectedItem.setTotal(CommonUtil.format2(money.floatValue()));
        this.salesReceiptsMainController.getTableView().refresh();
        this.salesReceiptsMainController.countMoney();
        this.cancelAction();
    }

    @FXML
    private void cancelAction() {
        this.pane.getScene().getWindow().hide();
    }
}

